<template>
  <div class="todo-header">
    <input type="text" placeholder="请输入你的任务名称，按回车键确认" 
    v-model="inputValue" 
    @keyup="handlePrint($event)"/>
  </div>
</template>

<script>
import {nanoid} from 'nanoid'
export default{
  data(){
    return {
      inputValue: ''
    }
  },
  methods:{
    handlePrint(e){
      if(e.keyCode !== 13) return
      console.log(e.keyCode,this.inputValue)
      const todoObj = {id:nanoid(),name:this.inputValue,done:false}
      this.$emit('addTodo',todoObj) 
    }
  }
}
</script>

<style>
</style>
